package com.zx.dsptuneup_TriMic.widget.ui;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.xujiaji.happybubble.BubbleDialog;
import com.xujiaji.happybubble.BubbleLayout;
import com.xujiaji.happybubble.Util;
import com.zx.dsptuneup_TriMic.R;

public class CustomOperateDialog extends BubbleDialog implements View.OnClickListener {
    private ViewHolder mViewHolder;
    private OnClickCustomButtonListener mListener;
    private TextView lastSelText = null;

    public CustomOperateDialog(Context context) {

        super(context);
        BubbleLayout bl = new BubbleLayout(context);
        bl.setBubbleColor(getContext().getResources().getColor(R.color.freq_tag));
        bl.setShadowColor(R.color.home_bg);
        bl.setBubblePadding(0);
        bl.setLookLength(Util.dpToPx(getContext(), 8));
        bl.setLookWidth(Util.dpToPx(getContext(), 16));
        bl.setBubbleRadius(Util.dpToPx(getContext(), 3));

        setBubbleLayout(bl);
        View rootView = LayoutInflater.from(context).inflate(R.layout.tree_operation, null);
        mViewHolder = new ViewHolder(rootView);
        addContentView(rootView);
        mViewHolder.btn13.setOnClickListener(this);
        mViewHolder.btn14.setOnClickListener(this);
        mViewHolder.btn15.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        TextView txt = (TextView)v;
        if (mListener != null) {
            mListener.onOperationItemClick(((TextView)v).getText().toString(),(int)txt.getTag());
        }

        if(lastSelText == null){
            txt.setSelected(true);
            lastSelText = txt;
            return;
        }else {
             if(lastSelText == txt) {
                 return;
             }else {
                 lastSelText.setSelected(false);
                 txt.setSelected(true);
                 lastSelText = txt;
             }
        }

    }

    private static class ViewHolder {
        TextView btn13, btn14, btn15;
        public ViewHolder(View rootView) {
            btn13 = rootView.findViewById(R.id.button13);
            btn13.setTag(0);
            btn14 = rootView.findViewById(R.id.button14);
            btn14.setTag(1);
            btn15 = rootView.findViewById(R.id.button15);
            btn15.setTag(2);
        }
    }

    public void setClickListener(OnClickCustomButtonListener l) {
        this.mListener = l;
    }

    public interface OnClickCustomButtonListener {
        void onOperationItemClick(String str,int index);
    }
}
